package com.itcam.pro01;

/**
 * @author : Cammy.Wu
 * Description : 
 */

public class Demo01Lambda {
    public static void main(String[] args) {
        // 1.自己创建实现对象
        MyInterfaceImpl myInterface = new MyInterfaceImpl();
        System.out.println(myInterface.sum(5, 9));

        // 2.创建匿名实现类
        MyInterface myInterface1 = new MyInterface() {

            @Override
            public int sum(int i, int j) {
                return i * j;
            }
        };
        System.out.println(myInterface1.sum(5, 5));

        // 3.lambda表达式：参数列表 + 箭头 + 方法体
        MyInterface myInterface2 = (x, y) -> {
            return x * x + y * y;
        };
        System.out.println(myInterface2.sum(3, 4));

        MyInterfaceDouble myInterfaceDouble = () -> {
            return 5;
        };
        System.out.println(myInterfaceDouble.func());

        MyInterfaceDouble myInterfaceDouble1 = () -> 1;
        System.out.println(myInterfaceDouble1.func());
    }
}

interface MyInterface {
    int sum(int i, int j);
}

@FunctionalInterface // 检查注解，帮我们快速检查我们写的接口是否函数式接口
interface MyInterfaceDouble {
    int func();

    default int power() {
        return 2;
    }

    ;
}

interface MyInterfaceThr {
    void func(int i, int j, int k);
}

class MyInterfaceImpl implements MyInterface {

    @Override
    public int sum(int i, int j) {
        return i + j;
    }
}
